
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"

class subscriber: public rclcpp::Node
{

public:
    subscriber(std::string name):Node(name)
    {
        RCLCPP_INFO(this->get_logger(), "I am %s", name.c_str());
        subscriber_ = this->create_subscription<std_msgs::msg::String>("command", 10,
            std::bind(&subscriber::command_callback, this, std::placeholders::_1));
        
    }
    ~subscriber()
    {

    }
private:
    void command_callback(const std_msgs::msg::String::SharedPtr msg)
    {
        RCLCPP_INFO(this->get_logger(), "Subscrib: %s", msg->data.c_str());
    }

private:
    rclcpp::Subscription<std_msgs::msg::String>::SharedPtr subscriber_;
};


int main(int argc, char **argv)
{
    rclcpp::init(argc, argv);

    auto node = std::make_shared<subscriber>("subscriber");
    RCLCPP_INFO(node->get_logger(), "subscriber start");
    rclcpp::spin(node);
    rclcpp::shutdown();
    return 0;

}